var app = getApp();
var QQMapWX = require('qqmap-wx-jssdk.js');
Page({
  data: {
    hotel: [],
    address: '',
    searchAddress: ''
  },
  onLoad: function(o) {
    var that = this;
    that.setData({
      searchAddress: o.address ? o.address : ''
    });
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#3090F4'
    });
    // 实例化API核心类
    var qqmapsdk = new QQMapWX({
      key: 'DXJBZ-ZQEKW-UOPRE-RAZT3-CI6NK-WOBF5'
    });
    //1、获取当前位置坐标
    wx.getLocation({
      type: 'wgs84',
      success: function(res) {
        //2、根据坐标获取当前位置名称，显示在顶部:腾讯地图逆地址解析
        qqmapsdk.reverseGeocoder({
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          },
          success: function(addressRes) {
            var address = addressRes.result.formatted_addresses.recommend;
            console.log(address);
            that.setData({
              address: address,
              latitude: res.latitude,
              longitude: res.longitude
            })
          },
          fail: function(e) {
            console.log(e);
          },
          complete: function(e) {
            console.log(e);
          }
        })
      }
    })
  },
  search_hotel: function(o) {
    console.log(o);
  },
  local: function() {

  },
  search_result: function(o) {

  },
  onReady: function() {},
  onShow: function() {},
  onHide: function() {
    this.setData({
      hotel: []
    });
  },
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {}
});